package cn.pugle.oj.leetcode;

import cn.pugle.oj.catalog.StackProblem;
import cn.pugle.oj.catalog.Unknown;

import java.util.LinkedList;

/**
 * 可以用两个队列
 * 这里用一个队列
 * 两个栈模拟队列, 两个队列模拟栈
 * 225 232
 *
 * @author tzp
 * @since 2020/11/18
 */
public class LC225 implements StackProblem {

    class MyStack {
        LinkedList<Integer> queue;

        /**
         * Initialize your data structure here.
         */
        public MyStack() {
            queue = new LinkedList<>();
//            queue.offerLast();
//            queue.removeFirst();
//            queue.peekFirst();
        }

        //循环倒腾
        public void push(int x) {
            queue.offerLast(x);
            int n = queue.size();
            for (int i = 0; i < n - 1; i++) {
                queue.offerLast(queue.removeFirst());
            }
        }


        public int pop() {
            return queue.removeFirst();
        }


        public int top() {
            return queue.getFirst();
        }

        public boolean empty() {
            return queue.size() == 0;
        }
    }

    public static void main(String[] args) {
        System.out.println(new LC225());
    }
}
